package com.jade.journal.impl;

import com.jade.framework.base.pattern.pipeline.Pipeline;
import com.jade.journal.JournalEvent;
import com.jade.journal.JournalHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 采用管道的日志处理器。
 *
 * @author sky
 * @version 1.0 14-9-22 下午5:25
 */
public class PipelineHandler implements JournalHandler
{
    protected Pipeline<JournalEvent[], Exception> pipeline;
    protected Log log = LogFactory.getLog(PipelineHandler.class);

    public void setPipeline(Pipeline<JournalEvent[], Exception> pipeline)
    {
        this.pipeline = pipeline;
    }

    public void handle(JournalEvent... events)
    {
        try {
            pipeline.handle(events);
        }
        catch (Throwable t) {
            log.error("Can't handle journal:", t);
        }
    }
}
